<?php


namespace App\Http\Services\Admin;


use App\Http\Constants\CreditsAdminOplogConstants;
use App\Models\CreditsAdminOplog;
use YiluTech\ComplexSearch\ComplexSearch;

class CreditsAdminOplogService extends ComplexSearch
{

    public $root = CreditsAdminOplog::class;

    protected $orderBy = 'id desc';

    protected $display = 'simple';

    protected $headers = [
        ['label' => 'ID', 'value' => 'id'],
        ['label' => '业务ID', 'value' => 'business_id'],
        ['label' => '操作人ID', 'value' => 'user_id'],
        ['label' => '操作人姓名', 'value' => 'username'],
        ['label' => '操作人手机号', 'value' => 'mobile'],
        ['label' => '操作模块', 'value' => 'module_type'],
        ['label' => '操作类型', 'value' => 'action_type'],
        ['label' => 'IP', 'value' => 'ip'],
        ['label' => '修改前的数据', 'value' => 'old_data'],
        ['label' => '修改后的数据', 'value' => 'new_data'],
        ['label' => '创建时间', 'value' => 'created_at'],
        ['label' => '更新时间', 'value' => 'updated_at'],

    ];

    protected $conditions = [
        'module_type' => [
            'ctype' => 'select',
            'operator' => CreditsAdminOplogConstants::MODULES,
            'label' => '操作模块',
        ],
        'username' => [
            'ctype' => 'input',
            'operator' => 'like',
            'label' => '操作人姓名',
        ],
        'mobile' => [
            'ctype' => 'input',
            'operator' => '=',
            'label' => '操作人手机号',
        ],
        'created_at' => [
            'ctype' => 'date-in',
            'display' => true,
            'format' => 'Y-m-d',
            'label' => '创建时间',
        ],
    ];

    public function query()
    {
        $select = ['id','username','mobile','ip','module_type','action_type','created_at'];
        $query = parent::query();
        $query->select($select);
        return $query;

    }


    public function detail($id)
    {
        $data =  CreditsAdminOplog::find($id)->toArray();
        $instance = resolve($data['module_type'], $data);
        return $instance->getData();
    }

}
